package cn.m3a1.service.teacher;

import cn.m3a1.bean.*;
import cn.m3a1.dao.AbsentNoteMapper;
import cn.m3a1.dao.CurseMapper;
import cn.m3a1.dao.TclassMapper;
import cn.m3a1.dao.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wyj
 * @date 2019/7/18
 * @time 下午12:25
 */
@Service
public class TeacherService {
    @Autowired
    CurseMapper curseMapper;
    @Autowired
    UserMapper userMapper;
    @Autowired
    AbsentNoteMapper absentNoteMapper;

    /**
     * 根据教师的id获取他所带的课程的信息
     *
     * @param teacherId
     * @return
     */
    public List<Curse> getCurse(int teacherId) {
        List<Curse> curses = curseMapper.selectByTeaId(teacherId);
        return curses;
    }

    /**
     * 根据班级id查询班级学生信息
     *
     * @param classId
     * @return
     */
    public List<User> getUserByTclass(int classId) {
        List<User> users = userMapper.selectByExamplewithstu(classId);
        return users;
    }

    /**
     * 教师获取需要自己修改的假条
     *
     * @return
     */
    public List<AbsentNote> getLeave(int teacherid) {
        List<AbsentNote> absentNotes = absentNoteMapper.selectByTeacherWithUser(teacherid);
        return  absentNotes;
    }

    /**
     * 根据假条的id返回假条的信息
     * @param id
     * @return
     */
    public  AbsentNote getAbsent(int id){
        AbsentNoteExample absentNoteExample=new AbsentNoteExample();
        AbsentNoteExample.Criteria criteria = absentNoteExample.createCriteria();
        criteria.andIdEqualTo(id);
        List<AbsentNote> absentNotes = absentNoteMapper.selectByExample(absentNoteExample);
        if (absentNotes==null){
            return null;
        }
        return absentNotes.get(0);
    }
    /**
     * 教师审批需要自己审批的请假单
     *
     * @return
     */
    public boolean setLeave(AbsentNote absentNote) {

        AbsentNoteExample absentNoteExample=new AbsentNoteExample();
        AbsentNoteExample.Criteria criteria = absentNoteExample.createCriteria();
        criteria.andIdEqualTo(absentNote.getId());
        int i = absentNoteMapper.updateByExampleSelective(absentNote, absentNoteExample);
        return i==1;
    }


}
